#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: connectDB.py
@time: 2017/9/6 17:10
"""

import pymysql
import sys

class MysqlConnect(object):
	def __init__(self,host,port,user,passwd):
		self.host = host
		self.port = port
		self.user = user
		self.passwd = passwd
		try:
			self.conn = pymysql.connect(host=self.host, port=int(self.port), user=self.user, passwd=self.passwd,charset='utf8')
		except:
			print('mysql cannot connect！')
			sys.exit(2)

	def connectdb(self):
		cursor = self.conn.cursor()
		return cursor

	def getvalue(self,cursor,commad):
		cursor.execute(commad)
		result = cursor.fetchall()
		return result

	def closeconnect(self):
		self.conn.close()

def main():

	dbobj = MysqlConnect('192.168.6.248','3306','Testers','Testers')
	dbconn = dbobj.connectdb()

	if len(sys.argv) < 2:
		print('参数不足')
		sys.exit(2)
	commad = "SHOW STATUS LIKE '%s';" % sys.argv[1]
	result = dbobj.getvalue(dbconn,commad)
	print(result)
	dbobj.closeconnect()


if __name__ == '__main__':
	main()